package pl.jug.trojmiasto.luceneExample;

import java.io.File;
import java.io.IOException;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericField;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;

public class IndexerExample {

	public static void main(String[] args) throws IOException {

		IndexWriterConfig iConfig = new IndexWriterConfig(Version.LUCENE_36,
				new StandardAnalyzer(Version.LUCENE_36));
		iConfig.setOpenMode(OpenMode.CREATE);
		Directory dir = FSDirectory.open(new File("/tmp/jug/images-index/"));
		
		IndexWriter writer = new IndexWriter(dir, iConfig);
		
		String[] nazwa = {"lucene", "luke", "solr"};
		String[] opis = {"logo Lucene", "logo Luke'a - czytnika indeksów Lucene", "logo Solra - serwera wyszukiwawczego opartego na Lucene"};
		Float[] proporcja = {6.5f, 1.4f, 1.8f};
		
		for (int i = 0; i < nazwa.length; i++) {
			Document doc = new Document();
			doc.add(new Field("nazwa", nazwa[i], Store.YES, Index.ANALYZED));
			doc.add(new Field("opis", opis[i], Store.YES, Index.ANALYZED));
			doc.add(new NumericField("proporcja", Store.YES, true).setFloatValue(proporcja[i]));
			
			writer.addDocument(doc);
		}

		writer.close();
	}

}
